﻿using Contract.Infrastructure.Repository;
using Contract.WebApi.Application.Commands;
using MediatR;

namespace Contract.WebApi.Application.CommandHandler
{
    public class DelsTYContractCommandHandler : IRequestHandler<DelsTYContractCommands, int>
    {
        private readonly IRepository<Domain.Contract> _repository;

        public DelsTYContractCommandHandler(IRepository<Domain.Contract> repository)
        {
            _repository = repository;
        }

        public async Task<int> Handle(DelsTYContractCommands request, CancellationToken cancellationToken)
        {
            int ind = 0;
            foreach (var i in request.Ids)
            {
                var info = await _repository.GetAsync(i);
                info.IsDel = true;
                info.UpdateDate = DateTime.Now;
                ind += await _repository.UpdateAsync(info);
            }
            return ind;
        }
    }
}
